import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const router = new Router({
  mode: 'history',
  // base: process.env.BASE_URL,
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    // 首页
    {
      path: '/msite',
      name: 'Msite',
      component: () => import('../views/Msite/Msite')
    },
    // 详情页
    {
      path: '/details',
      name: 'Details',
      component: () => import('../views/Msite/Details')
    },
    // 车辆搜索
    {
      path: '/search',
      name: 'Search',
      component: () => import('../views/Msite/Search')
    },
    // 租车GPS
    {
      path: '/rental',
      name: 'Rental',
      component: () => import('../views/Msite/Rental')
    },
    // 收藏
    {
      path: '/collection',
      name: 'Collection',
      component: () => import('../views/Collection/Collection')
    },
    // 订单
    {
      path: '/order',
      name: 'Order',
      component: () => import('../views/Order/Order')
    },
    // 我的
    {
      path: '/profile',
      name: 'Profile',
      component: () => import('../views/Profile/Profile')
    },
    // 登录
    {
      path: '/login',
      name: 'Login',
      component: () => import('../views/Login')
    },
    // 登录
    {
      path: '/loginphone',
      name: 'LoginPhone',
      component: () => import('../views/LoginPhone')
    },
    // 注册
    {
      path: '/register',
      name: 'Register',
      component: () => import('../views/Register')
    },
    // {
    //   path: '/walletdetail?title=',
    //   name: 'Walletdetail',
    //   component: () => import('../views/Profile/Details')
    // }
    // 钱包详情页
    {
      path: '/walletdetail',
      name: 'Walletdetail',
      component: () => import('../views/Profile/Details')
    },
    // 、功能
    {
      path: '/function',
      name: 'Function',
      component: () => import('../views/Profile/Function')
    },
    // 设置
    {
      path: '/setting',
      name: 'Setting',
      component: () => import('../views/Profile/Setting')
      // children: [
      //   {
      //     path: '/setting/settingdetails',
      //     name: 'SettingDetails',
      //     component: () => import('../views/Profile/SettingDetails')
      //   }
      // ]
    },
    {
      path: '/setting/settingdetails',
      name: 'SettingDetails',
      component: () => import('../views/Profile/SettingDetails')
    },
    // 消息通知
    {
      path: '/message',
      name: 'Message',
      component: () => import('../views/Profile/Message')
    }
  ]
});
// router.beforeEach((to, from, next) => {
//   if(to.path === '/login') return next();
//   let userInfo = this.$cookie.get('username'); // 获取用户信息
//   if(!userInfo) return next('/login'); // 如果用户数据为null, 则跳转到指定路径
//   next()
// })

export default router;